package dtos;

import java.util.List;

import org.hibernate.validator.constraints.NotEmpty;

public class PredefinedTPDTO {
	
	@NotEmpty
	private int travelID;
	
	private List<ExcursionDTO> excursions;
	
	private HotelDTO hotelBean;
	
	private MeanOfTransportationDTO meanOfTransportation1;
	
	private MeanOfTransportationDTO meanOfTransportation2;
	
	private UserDTO user;
	
	
	
	
	public PredefinedTPDTO(){
		
	}
	
	public int getID(){
		return travelID;
	}
	
	public int getPrice(int numberNights){
		int price = this.hotelBean.getCost()*(numberNights) + this.getMeanOfTransportation1().getCost() + this.getMeanOfTransportation2().getCost();
		for (ExcursionDTO e : excursions){
			price = price + e.getCost();
		}
		return price;
	}
	
	public int getTravelID() {
		return this.travelID;
	}

	public void setTravelID(int travelID) {
		this.travelID = travelID;
	}

	public List<ExcursionDTO> getExcursions() {
		return this.excursions;
	}

	public void setExcursionsDTO(List<ExcursionDTO> excursions) {
		this.excursions = excursions;
	}

	public String getExcursionsList(){
		String res = "*** ";
		for (ExcursionDTO e : this.excursions){
			res = res + e.getName()+", meeting at "+e.getMeetingPlace()+", "+e.getMeetingTime()+" *** ";
		}
		return res;
	}
	
	public HotelDTO getHotelBean() {
		return this.hotelBean;
	}

	public void setHotelBean(HotelDTO hotelBean) {
		this.hotelBean = hotelBean;
	}

	public MeanOfTransportationDTO getMeanOfTransportation1() {
		return this.meanOfTransportation1;
	}

	public void setMeanOfTransportation1(MeanOfTransportationDTO meanOfTransportation1) {
		this.meanOfTransportation1 = meanOfTransportation1;
	}

	public MeanOfTransportationDTO getMeanOfTransportation2() {
		return this.meanOfTransportation2;
	}

	public void setMeanOfTransportation2(MeanOfTransportationDTO meanOfTransportation2) {
		this.meanOfTransportation2 = meanOfTransportation2;
	}

	public UserDTO getUser() {
		return this.user;
	}

	public void setUser(UserDTO user) {
		this.user = user;
	}

	public String isValid() {
		if ((this.hotelBean == null)||(this.meanOfTransportation1 == null)||(this.meanOfTransportation2 == null)){
			return "Empty Hotel or Mean of transportation";
		}
		else{
			if (!(this.hotelBean.getArrivalPlace().equals(this.meanOfTransportation1.getTrip().getArrivalPlace()))){
				return "Hotel not in the vacation place";
			}
			else{
				String dep1 = this.meanOfTransportation1.getTrip().getDeparturePlace();
				String dep2 = this.meanOfTransportation2.getTrip().getDeparturePlace();
				String ar1 = this.meanOfTransportation1.getTrip().getArrivalPlace();
				String ar2 = this.meanOfTransportation2.getTrip().getArrivalPlace();
				if (!((dep1.equals(ar2))&&(dep2.equals(ar1)))){
					return "Inconsistent means of transportation";
				}
				else{
					return "ok";
				}
			}
		}
	}


}
